package com.deepblue.image.maker.service.impl;

import cn.hutool.core.util.StrUtil;
import com.deepblue.image.maker.config.FreemakerProperties;
import com.deepblue.image.maker.constants.CommonConstants;
import com.deepblue.image.maker.domain.freemaker.Dockerfile;
import com.deepblue.image.maker.enums.BusinessEnum;
import com.deepblue.image.maker.service.DockerfileService;
import com.deepblue.image.maker.util.CommonResultUtil;
import com.deepblue.image.maker.util.FreemakerUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * TODO
 *
 * @author yymagicer
 * @version 1.0
 * @date 2021/11/9 上午10:47
 */
@Service
public class DockerfileServiceImpl implements DockerfileService {


    @Resource
    private FreemakerUtil freemakerUtil;


    @Resource
    private FreemakerProperties freemakerProperties;

    @Override
    public String create(Dockerfile dockerfile) {
        String outFilePath = dockerfile.getImageName()+StrUtil.DASHED+ CommonConstants.DOCKERFILE;
        try {
            freemakerUtil.write(freemakerProperties.getFtlName(),outFilePath,dockerfile);
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
        return outFilePath;
    }
}
